package com.example.zzbus.ui;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.zzbus.R;
import com.example.zzbus.base.BaseApplication;
import com.example.zzbus.db.UserOrder;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class OrderActivity extends AppCompatActivity {

    @Bind(R.id.list)
    RecyclerView list;
    BaseQuickAdapter mBaseQuickAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);
        ButterKnife.bind(this);
        setTitle("我的订单");
        list.setLayoutManager(new LinearLayoutManager(this));
        list.setAdapter(mBaseQuickAdapter=new BaseQuickAdapter<UserOrder,BaseViewHolder>(R.layout.order_item) {
            @Override
            protected void convert(BaseViewHolder helper, UserOrder item) {
                helper.setText(R.id.tv_state,"起点："+item.getStartaddress());
                helper.setText(R.id.tv_end,"终点："+item.getEndaddress());
                helper.setText(R.id.tv_time,"时间："+item.getTime());
                helper.setText(R.id.tv_money,"价格："+item.getMoney());
                helper.setOnClickListener(R.id.btn_pay, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=10000007");
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        OrderActivity.this.startActivity(intent);
                    }
                });
            }
        });
    }
    @Override
    protected void onResume() {
        super.onResume();
        List<UserOrder> list= BaseApplication.getmDaoSession().getUserOrderDao().queryBuilder().list();
        mBaseQuickAdapter.setNewData(list);
        Log.d("tt" ,"onResume: "+list.size());
    }
}
